/**
 * 拦截response，统一返回｛code：200，data：data｝
 */

angular.module('mamApp')
    .config(['$httpProvider', function ($httpProvider) {
        $httpProvider.interceptors.push([function () {
            return {
                'request': function (config, body) {
                    var userInfo = JSON.parse(localStorage.getItem('userInfo'));
                    if (userInfo) {
                        config.headers['X-Auth-Token'] = userInfo.token;
                    } else {
                        //localStorage.removeItem("userInfo");
                        //localStorage.setItem("orginUrl",window.location.href);
                        //window.location = 'http://' + window.location.host;
                    }

                    return config;
                },
                response: function (response) {
                    if (response.hasOwnProperty('data')) {
                        if (response.data.c == "u") {
                            var userInfo = JSON.parse(localStorage.getItem('userInfo'));
                            if(userInfo){
                                localStorage.setItem("orginUser", userInfo.userName);
                                localStorage.setItem("orginUrl", window.location.href);

                            }

                            window.location = '#/login';
                        } else {
                            return {code: response.status, data: response.data};

                        }

                    } else {
                        return response;
                    }
                }
            }
        }]);
    }]).value('api', "http://192.168.2.207:8080/mam_admin")

 //}]).value('api', "http://192.168.2.114:8080/AGX_MAM_ADMIN_API_V1")
/*}]).value('api', "http://192.168.2.68:8080/AGX_MAM_ADMIN_API_V1")*/


// }]).value('api', "http://192.168.2.195:8080/mam_admin")

